<?php
public function identify($account, $password)
{
    // admin登录时启用本地账号
    if ('admin' == $account) {
        return parent::identify(ltrim($account, '$'), $password);
    } else {
        // 进行LDAP用户验证
        $ldap = $this->loadModel('ldap');
        $dn = $ldap->getUserDN($this->config->ldap, $account);
        if (!$dn) {
            return false;
        }
        $pass = $ldap->identify($this->config->ldap, $dn, $password);
        if ('Success' == $pass){
            // 验证成功
            // 账户是否存在于禅道DB
            if ($ldap->isExistInZenTaoDB($account)){
                // 存在，更新用户信息并登录
				$data = $ldap->getUserMessageFromLDAP($this->config->ldap,$this->config->ldap->uid.'='.$account);
                $ldap->updateUserDB($this->config->ldap, $account, $password, $data);
                return parent::identify($account, $password);
            } else {
                // 不存在，添加到禅道DB后进行登录
                $data = $ldap->getUserMessageFromLDAP($this->config->ldap,$this->config->ldap->uid.'='.$account);
                $addUser = $ldap->addUserToZenTaoDB($this->config->ldap, $data, $password);
                // 设置用户默认权限
                $ldap->setDefaultUserGroup($account);
                return parent::identify($account, $password);
            }
        }
        // 验证失败
        return false;
    }
}
